package com.nutiteq.mapper.forms;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import com.nutiteq.MapComponent;
import com.nutiteq.mapper.MapScreen;
import com.nutiteq.mapper.Mapper;
import com.nutiteq.ui.DefaultCursor;

public class ChangeCursorList extends List implements CommandListener {
  private static final String[] CURSORS = new String[] { "Default (painted)", "The Finger (image)",
      "BullsEye (painted)" };
  private final MapComponent mapComponent;

  public static final Command CHANGE_CURSOR_COMMAND = new Command("Change cursor", Command.ITEM, 0);

  private Command back;
  private Command change;

  public ChangeCursorList(final MapComponent mapComponent) {
    super("Change cursor", List.IMPLICIT, CURSORS, null);
    this.mapComponent = mapComponent;

    back = new Command("Back", Command.BACK, 0);
    change = new Command("Change", Command.OK, 0);

    addCommand(back);
    addCommand(change);
    setSelectCommand(change);

    setCommandListener(this);
  }

  public void commandAction(final Command cmd, final Displayable d) {
    if (cmd == change) {
      final int selected = getSelectedIndex();
      System.out.println(selected);
      if (selected == 0) {
        mapComponent.setCursor(new DefaultCursor(0xFFFF0000));
      } else if (selected == 1) {
        mapComponent.setCursor(new FingerCursor());
      } else if (selected == 2) {
        mapComponent.setCursor(new BullsEyeCursor());
      }

      Display.getDisplay(Mapper.instance).setCurrent(MapScreen.instance);
    } else if (cmd == back) {
      Display.getDisplay(Mapper.instance).setCurrent(MapScreen.instance);
    }
  }
}
